﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Demos.DesignPatterns._18_迭代器模式
{
    /// <summary>
    /// 具体集合：书架
    /// </summary>
    public class BookShelf:IBookCollection
    {

        private readonly Book[] _books ;
        public BookShelf(int capacity)
        {
            _books = new Book[capacity];
        }

        public Book this[int index]
        {
            get => _books[index];
            set => _books[index] = value;
        }
        
        public int Count => _books.Length;  

        public IIterator<Book> CreateIterator()
        {
            return new BookShelfIterator(this);
        }

    }
}
